package com.junzhiit.nengji.cms.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.TagService;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;
import com.junzhiit.nengji.cms.web.vo.TagAddVO;
import com.junzhiit.nengji.cms.web.vo.TagEditVO;
import com.junzhiit.nengji.cms.web.vo.TagListVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("tag")
public class TagController extends BaseController{
	
	@Autowired
	private TagService tagService;
	
	@ApiOperation(value = "获取标签")
	@RequestMapping(method=RequestMethod.GET)
	public Map<String, Object> findAll(DataTablesParamVO dtp, TagListVO tagListVO){
		return tagService.findAll(dtp, tagListVO);
	}
	
	@ApiOperation(value="根据id获取标签")
	@RequestMapping(value="/{id}",method=RequestMethod.GET)
	public ResultVO findById(@PathVariable String id){
		return tagService.findById(id);
	}
	
	
	@RequestMapping(method=RequestMethod.POST)
	public ResultVO add(TagAddVO tagAddVO){
		AssertUtil.notBlank(tagAddVO.getName(), "name is required");
		AssertUtil.notBlank(tagAddVO.getDescribe(), "describe is required");
		return tagService.add(tagAddVO);
	}
	
	@RequestMapping(method=RequestMethod.PUT)
	public ResultVO edit(TagEditVO tagEditVO){
		return tagService.edit(tagEditVO);
	}
	
	@RequestMapping(value="/delete/{id}",method=RequestMethod.PUT)
	public ResultVO updateToDelete(@PathVariable String id){
		return tagService.updateToDelete(id);
	}
	
	@RequestMapping(value="/all",method=RequestMethod.GET)
	public ResultVO getAll(TagListVO tagListVO){
		return tagService.getAll(tagListVO);
	}
	
}
